package com.any.hook.core.webapi.service;

import com.any.hook.common.exception.HookException;
import com.any.hook.core.webapi.config.WebApiErrorCode;
import com.any.hook.core.webapi.entity.JobInfo;
import com.any.hook.core.webapi.mapper.JobInfoMapper;
import com.any.hook.core.webapi.util.JobStat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EtlJobService {
    @Autowired
    private JobInfoMapper jobInfoMapper;
    public String getContextByid(Long id){
        JobInfo jobInfo=jobInfoMapper.queryContextById(id);
        return jobInfo.getContext();
    }
    public int changeJobStat(Long id,JobStat stat) throws Exception{
        switch (stat){
            case JOB_STOP:
                return jobInfoMapper.changeStopStat(id);
            case JOB_START:
                return jobInfoMapper.changeStartStat(id);
            default:
                throw HookException.asHookException(WebApiErrorCode.API_RUNTIME_ERROR,"请联系开发人员，内部运行错误 .");
        }

    }
    public List<JobInfo> getAllJobInfo(int page, int size){
        int skipCount=(page-1)*size;
        return jobInfoMapper.queryAll(skipCount,size);
    }
    public int updateByObject(JobInfo jobInfo){
        return jobInfoMapper.updateInfo(jobInfo);
    }

    public int saveJobInfo(JobInfo jobInfo){
        return jobInfoMapper.insertInfo(jobInfo);
    }

    public int selectCount(){
        return jobInfoMapper.selectCount();
    }
    public int deleteById(Long id){return jobInfoMapper.deleteById(id);}
}
